<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<!ENTITY owl "http://www.w3.org/2002/07/owl#">
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
<!ENTITY op "urn:operon:cephb.fr/schema/">
<!ENTITY dc "http://purl.org/dc/elements/1.1/">
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema">
]>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:rdf="&rdf;"
	xmlns:owl="&owl;"
	xmlns:rdfs="&rdfs;"
	xmlns:dc="&dc;"
	xmlns:xsd="&xsd;"
	xmlns:op="&op;"
        xmlns:h="http://www.w3.org/1999/xhtml"
    >
<!--

Author Pierre Lindenbaum
Transforms a schema of operon to Mario's original Spreadsheet

-->
<xsl:output method="html" />
<xsl:key name="simpleTypes" match="/op:schema/op:SimpleType" use="@id"/>
<xsl:key name="complexTypes" match="/op:schema/op:ComplexType" use="@id"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="op:schema">
<html>
<body style="font-size:10pt;">
<table border="1.0" width="100%">
<thead>
<tr style="background-color:blue;color:white">
<th>PL</th>
<th>DO</th>
<th>Domain</th>
<th>Context</th>
<th>Database</th>
<th>SDB</th>
<th>AM</th>
<th>DK</th>
<th>PK</th>
<th>SK</th>
<th>TK</th>
<th>QK</th>
<th>ON</th>
<th>Key</th>
<th>Value</th>
<th>Type</th>
<th>LIM</th>
<th>Comment</th>
</tr>
</thead>
<tbody>


<!-- LOOP OVER ALL THE DATABASES -->

<xsl:for-each select="op:Database">
<xsl:variable name="database" select="."/>
<xsl:variable name="dbname" select="dc:title"/>
<xsl:variable name="domain" select="op:domain"/>
<xsl:variable name="context" select="dc:description[@xml:lang=&apos;en&apos;]"/>
<xsl:variable name="AM" select="op:database-type"/>


<xsl:variable name="PL">
<xsl:choose>
<xsl:when test="op:assembly-dependant = &apos;true&apos;">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:variable name="DK">
<xsl:choose>
<xsl:when test="op:allow-duplicate = &apos;true&apos;">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>



<!-- domain order -->
<xsl:variable name="DO">
<xsl:choose>
<xsl:when test="$domain = &apos;Application&apos;">0</xsl:when>
<xsl:when test="$domain = &apos;Projects&apos;">1</xsl:when>
<xsl:when test="$domain = &apos;CV&apos;">2</xsl:when>
<xsl:when test="$domain = &apos;DNA&apos;">3</xsl:when>
<xsl:when test="$domain = &apos;Genes&apos;">4</xsl:when>
<xsl:when test="$domain = &apos;Proteins&apos;">5</xsl:when>
<xsl:when test="$domain = &apos;Hypergraphs&apos;">6</xsl:when>
<xsl:otherwise><xsl:message terminate="yes" >domain ??:<xsl:value-of select="$domain"/></xsl:message></xsl:otherwise>
</xsl:choose>
</xsl:variable>


<xsl:variable name="PK">
<xsl:choose>
<xsl:when test="$domain = &apos;Application&apos;">0</xsl:when>
<xsl:when test="op:allow-duplicate = &apos;true&apos;">0</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:variable>




<xsl:variable name="key" select="key(&apos;simpleTypes&apos;,op:key-type/op:type/@ref)"/>
<xsl:variable name="values" select="key(&apos;complexTypes&apos;,op:value-type/op:type/@ref)"/>


<!-- FIRST ROW IS THE KEY -->
<tr style="background-color:gray;">
<td><xsl:value-of select="$PL"/></td>
<td><xsl:value-of select="$DO"/></td>
<td><xsl:value-of select="$domain"/></td>
<td><xsl:value-of select="$context"/></td>
<td><xsl:value-of select="$dbname"/></td>
<td/>
<td><xsl:value-of select="$AM"/></td>
<td><xsl:value-of select="$DK"/></td>
<td><xsl:value-of select="$PK"/></td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td><xsl:value-of select="op:key-type/dc:title"/></td>
<td></td>
<td><xsl:value-of select="$key/op:type[ @language=&apos;C&apos;]"/></td>
<td><xsl:value-of select="op:key-type/op:expect-size"/></td>
<td><xsl:value-of select="op:key-type/dc:description"/></td>
</tr>

<!-- LOOP OVER ALL THE FIELDS -->
<xsl:for-each select="$values/op:fields/op:Field">
<xsl:variable name="key2" select="key(&apos;simpleTypes&apos;,op:type/@ref)"/>
<xsl:variable name="fieldName" select="dc:title"/>
<tr>
<td><xsl:value-of select="$PL"/></td>
<td><xsl:value-of select="$DO"/></td>
<td><xsl:value-of select="$domain"/></td>
<td><xsl:value-of select="$context"/></td>
<td><xsl:value-of select="$dbname"/></td>
<td>
<xsl:for-each select="$database/op:secondary-db/op:SecondaryDatabase">
<xsl:if test="@on-field-name = $fieldName">
<xsl:value-of select="dc:title"/>
</xsl:if>
</xsl:for-each>
</td>
<td><xsl:value-of select="$AM"/></td>
<td><xsl:value-of select="$DK"/></td>
<td><xsl:value-of select="$PK"/></td>

<!-- SK -->
<td>
<xsl:choose>
<xsl:when test="$database/op:secondary-db[1]/op:SecondaryDatabase[@on-field-name = $fieldName]">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</td>

<!-- TK -->
<td>
<xsl:choose>
<xsl:when test="$database/op:secondary-db[2]/op:SecondaryDatabase[@on-field-name = $fieldName]">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</td>


<!-- QK -->
<td>
<xsl:choose>
<xsl:when test="$database/op:secondary-db[3]/op:SecondaryDatabase[@on-field-name = $fieldName]">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</td>


<td><xsl:value-of select="position()"/></td>
<td></td>
<td><xsl:value-of select="$fieldName"/></td>
<td><xsl:value-of select="$key2/op:type[ @language=&apos;C&apos;]"/></td>
<td><xsl:value-of select="op:expect-size"/></td>
<td><xsl:value-of select="dc:description"/></td>
</tr>
</xsl:for-each>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>
